package avicit.im.lantop.basic.useconfig.action;

import avicit.cbb.appreg.service.CommSysInfoIntfsService;
import avicit.im.lantop.basic.useconfig.domain.LantopHighSet;
import avicit.im.lantop.basic.useconfig.service.UseConfigService;
import avicit.im.lantop.basic.useconfig.service.api.UseConfigServiceApi;
import avicit.im.lantop.useconfig.service.UseSetIntfsService;
import avicit.platform6.api.session.SessionHelper;
import avicit.platform6.api.syslookup.SysLookupAPI;
import avicit.platform6.api.syslookup.dto.SysLookupSimpleVo;
import avicit.platform6.api.syslookup.impl.SysLookupAPImpl;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.spring.SpringFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.util.*;

/**
 * <p>金航数码科技有限责任公司</p>
 * <p>作者：胡光昌</p>
 * <p>邮箱：huguangc@avicit.com</p>
 * <p>创建时间： 2014-10-15 下午3:06:44 </p>
 * <p>类说明：利用配置的控制器类</p>
 * <p>修改记录： </p>
 */
@Controller
@RequestMapping(value = "/UseConfigController")
@SuppressWarnings("deprecation")
public class UseConfigController {

	@Autowired(required = true)
	private UseConfigServiceApi useConfigService;

	@Autowired(required = true)
	private UseSetIntfsService useSetIntfsService;

	@Autowired(required = true)
	private CommSysInfoIntfsService commSysInfoIntfsService;

	private String sysId;

	// 获取利用类型通用代码
	SysLookupAPI upLoader = SpringFactory.getBean(SysLookupAPImpl.class);

	 Collection<SysLookupSimpleVo> lantopUseTypeList = upLoader.getLookUpListByType("LANTOP_USE_TYPE");
	 Collection<SysLookupSimpleVo> secretLevelList = upLoader.getLookUpListByType("CBB_SECRET");

	/**
	 * 更新数据配置信息 create by zxl
	 * @return
	 */
	@RequestMapping("/updataUseData")
	@ResponseBody
	public Map<String,Object> updataUseData(HttpServletRequest request, @RequestParam(value = "sysId") String sysId){
		// 更新方式：先删除本全宗配置数据信息，然后再新增
		String deptId = ThreadContextHelper.getOrgId();
		String orgId = ThreadContextHelper.getOrgId();
		useConfigService.deleteUseData(sysId,deptId,orgId);
		return new HashMap<>();
	}

	/**
	 * 初始化页面数据 create by zxl
	 * @param request
	 * @param sysId 系统ID
	 * @return
	 */
	@RequestMapping("/selectUserConfig")
	@ResponseBody
	public Map<String,Object> selectUserConfig(HttpServletRequest request,
                                         @RequestParam(value = "sysId") String sysId){
		Map<String,Object> params = new HashMap<>();
		String deptId = ThreadContextHelper.getDeptId();
		String orgId = ThreadContextHelper.getOrgId();
		List<Map<String,Object>> result = useConfigService.selectUserConfig(sysId,deptId,orgId);
		params.put("result",result);
		return params;
	}

	/**
	 * 保存档案利用配置信息
	 * @param req
	 * @return map
	 */
	@RequestMapping("/saveArchivalMessage")
	@ResponseBody
	@Transactional(rollbackFor = Exception.class)
	public Map<String,Object> saveArchivalMessage(HttpServletRequest req) {
		Map<String,Object> params = new HashMap<>();
		LantopHighSet ltht = new LantopHighSet();
		String appointmentArsDays = req.getParameter("appointmentArsDays");
		String downloadDefaultUseDays = req.getParameter("download_defaultUseDays");
		String downloadDefaultBorrowDays = req.getParameter("download_defaultBorrowDays");
		String printingDefaultUseDays = req.getParameter("printing_defaultUseDays");
		String printingDefaultBorrowDays = req.getParameter("printing_defaultBorrowDays");
		String browseDefaultUseDays = req.getParameter("browse_defaultUseDays");
		String browseDefaultBorrowDays = req.getParameter("browse_defaultBorrowDays");
		String borrowingDefaultUseDays = req.getParameter("borrowing_defaultUseDays");
		String borrowingDefaultBorrowDays = req.getParameter("borrowing_defaultBorrowDays");
		String borrowingDefaultUrgeDays = req.getParameter("borrowing_defaultUrgeDays");
		/* 新增浏览无水印，下载无水印，纸质原件 */
		String borrowingNoWatermarkdefaultUseDays = req.getParameter("borrowingNoWatermarkdefaultUseDays");
		String borrowingNoWatermarkdefaultBorrowDays = req.getParameter("borrowingNoWatermarkdefaultBorrowDays");
		String borrowingNoWatermarkdefaultUrgeDays = req.getParameter("borrowingNoWatermarkdefaultUrgeDays");

		String downloadNoWatermarkdefaultUseDays = req.getParameter("downloadNoWatermarkdefaultUseDays");
		String downloadNoWatermarkdefaultBorrowDays = req.getParameter("downloadNoWatermarkdefaultBorrowDays");
		String downloadNoWatermarkdefaultUrgeDays = req.getParameter("downloadNoWatermarkdefaultUrgeDays");

		String downloadPaperdefaultUseDays = req.getParameter("downloadPaperdefaultUseDays");
		String downloadPaperdefaultBorrowDays = req.getParameter("downloadPaperdefaultBorrowDays");
		String downloadPaperdefaultUrgeDays = req.getParameter("downloadPaperdefaultUrgeDays");
		sysId = req.getParameter("sysId");
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getDeptId();
		try {
			/** 档案鉴定日期不为空，赋值利用类型，添加利用信息 */
			if (appointmentArsDays != null && !"".equals(appointmentArsDays)) {
				ltht.setUseType("JD");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), null, null, null, appointmentArsDays);
			}
			/** 判断下载-利用日期和续借天数不为空, 添加利用信息*/
			if (downloadDefaultUseDays != null && !"".equals(downloadDefaultUseDays) || downloadDefaultBorrowDays != null && !"".equals(downloadDefaultBorrowDays)) {
				ltht.setUseType("XZ");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), downloadDefaultUseDays, downloadDefaultBorrowDays, null, null);
			}
			/** 判断打印-利用日期和续借天数不为空, 添加利用信息 */
			if (printingDefaultUseDays != null && !"".equals(printingDefaultUseDays) || printingDefaultBorrowDays != null && !"".equals(printingDefaultBorrowDays)) {
				ltht.setUseType("DY");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), printingDefaultUseDays, printingDefaultBorrowDays, null, null);
			}
			/** 判断浏览-利用日期和续借天数不为空, 添加利用信息 */
			if (browseDefaultUseDays != null && !"".equals(browseDefaultUseDays) || browseDefaultBorrowDays != null && !"".equals(browseDefaultBorrowDays)) {
				ltht.setUseType("LL");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), browseDefaultUseDays, browseDefaultBorrowDays, null, null);
			}
			/** 判断-利用日期和续借天数不为空, 添加利用信息 */
			if (borrowingDefaultUseDays != null && !"".equals(borrowingDefaultUseDays) || borrowingDefaultBorrowDays != null && !"".equals(borrowingDefaultBorrowDays) || borrowingDefaultUrgeDays != null && !"".equals(borrowingDefaultUrgeDays)) {
				ltht.setUseType("JY");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), borrowingDefaultUseDays, borrowingDefaultBorrowDays, borrowingDefaultUrgeDays, null);
			}
			/** 判断-浏览（无水印）：利用天数 ，续借天数，提前催还天数**/
			if (borrowingNoWatermarkdefaultUseDays !=null && !"".equals(borrowingNoWatermarkdefaultUseDays)||borrowingNoWatermarkdefaultBorrowDays !=null && !"".equals(borrowingNoWatermarkdefaultBorrowDays)||borrowingNoWatermarkdefaultUrgeDays !=null && !"".equals(borrowingNoWatermarkdefaultUrgeDays)){
				ltht.setUseType("LLWSY");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), borrowingNoWatermarkdefaultUseDays, borrowingNoWatermarkdefaultBorrowDays, borrowingDefaultUrgeDays, null);
			}
			/** 判断-下载（无水印）：利用天数 ，续借天数，提前催还天数**/
			if (downloadNoWatermarkdefaultUseDays !=null && !"".equals(downloadNoWatermarkdefaultUseDays)||downloadNoWatermarkdefaultBorrowDays !=null && !"".equals(downloadNoWatermarkdefaultBorrowDays)||downloadNoWatermarkdefaultUrgeDays !=null && !"".equals(downloadNoWatermarkdefaultUrgeDays)){
				ltht.setUseType("XZWSY");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), downloadNoWatermarkdefaultUseDays, downloadNoWatermarkdefaultBorrowDays, downloadNoWatermarkdefaultUrgeDays, null);
			}
			/** 判断-纸质原件：利用天数 ，续借天数，提前催还天数**/
			if (downloadPaperdefaultUseDays !=null && !"".equals(downloadPaperdefaultUseDays)||downloadPaperdefaultBorrowDays !=null && !"".equals(downloadPaperdefaultBorrowDays)||downloadPaperdefaultUrgeDays !=null && !"".equals(downloadPaperdefaultUrgeDays)){
				ltht.setUseType("ZZYJ");
				useConfigService.createArchivalMessage(sysId, orgId, deptId, ltht.getUseType(), downloadPaperdefaultUseDays, downloadPaperdefaultBorrowDays, downloadPaperdefaultUrgeDays, null);
			}
			return (Map<String, Object>) params.put("success", "1");
		} catch (Exception e) {
			e.printStackTrace();
			return (Map<String, Object>) params.put("success", "0");
		}
	}

	/**
	 * 查找启动高级设置的列表数据
	 * 
	 * @author 胡光昌  
	 * @param request
	 * @return
	 * @throws Exception
	 *             ModelAndView
	 * @throws
	 */
	@RequestMapping("/findSetInfo")
	public ModelAndView findSetInfo(HttpServletRequest request) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setView(null);
		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getOrgId();
		if (null == this.sysId || "".equals(this.sysId)) {
			this.sysId = request.getParameter("sysId");
		}
		String sysId = "LANTOP";
		String pageNo = request.getParameter("page");
		String pageSize = request.getParameter("rows");
		pageSize = "1000";
		Page<Map<String, Object>> page = new Page<Map<String, Object>>();
		page.setRows(ComUtil.getPageSize(pageSize));
		page.setPage(ComUtil.getPageNo(pageNo));
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("sysId", sysId);
		params.put("orgId", orgId);
		params.put("deptId", deptId);
		Collection<SysLookupSimpleVo> useTypeList = upLoader.getLookUpListByType("LANTOP_USE_TYPE");
		Collection<SysLookupSimpleVo> secretList = upLoader.getLookUpListByType("CBB_SECRET");
		params.put("useTypeList", useTypeList);
		params.put("secretList", secretList);
		this.useConfigService.doInitHighSetDatas(params);
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("sysId", sysId);
		param.put("orgId", orgId);
		// 添加参数获取对应密级和利用类型的数据
		param.put("useTypeList", useTypeList);
		param.put("secretList", secretList);
		this.useConfigService.findSetInfo(page, param);
		mav.addObject("total", page.getEntityCount());
		mav.addObject("rows", page.getEntities());
		return mav;
	}

	/**
	 * 保存配置信息
	 * 
	 * @author 胡光昌
	 * @param request
	 * @param response
	 * @return ModelAndView
	 * @throws Exception
	 */
	@RequestMapping("/saveSetInfo")
	public ModelAndView saveSetInfo(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setView(null);

		String defaultUseDays = request.getParameter("defaultUseDays");
		String defaultBorrowDays = request.getParameter("defaultBorrowDays");
		String defaultBorrowNum = request.getParameter("defaultBorrowNum");
		String borrowForcastDays = request.getParameter("borrowForcastDays");

		String defaultBorrowType = request.getParameter("defaultBorrowType");
		String isHighSet = request.getParameter("isHighSet");

		String isBorrowForcast = request.getParameter("isBorrowForcast");
		String forcastQueueNum = request.getParameter("forcastQueueNum");
		String forcastOvertime = request.getParameter("forcastOvertime");
		String psnMsgMaxRcds = request.getParameter("psnMsgMaxRcds");

		String sendEmailCount = request.getParameter("sendEmailCount");
		String password = request.getParameter("password");
		String isEmail = request.getParameter("isEmail");
		String sendSvr = request.getParameter("sendSvr");
		String sendPort = request.getParameter("sendPort");
		String rcvSvr = request.getParameter("rcvSvr");
		String rcvPort = request.getParameter("rcvPort");

		sysId = request.getParameter("sysId");

		Map<String, String> map = new HashMap<String, String>();

		map.put("DEFAULT_USE_DAYS", defaultUseDays);
		map.put("DEFAULT_BORROW_DAYS", defaultBorrowDays);
		map.put("DEFAULT_BORROW_NUM", defaultBorrowNum);
		map.put("BORROW_FORCAST_DAYS", borrowForcastDays);
		map.put("DEFAULT_BORROW_TYPE", defaultBorrowType);
		map.put("IS_HIGH_SET", isHighSet);
		map.put("IS_BORROW_FORCAST", isBorrowForcast);
		map.put("FORCAST_QUEUE_NUM", forcastQueueNum);
		map.put("FORCAST_OVERTIME", forcastOvertime);
		map.put("PSN_MSG_MAX_RCDS", psnMsgMaxRcds);
		map.put("IS_EMAIL", isEmail);
		map.put("SEND_SVR", sendSvr);
		map.put("SEND_PORT", sendPort);
		map.put("RCV_SVR", rcvSvr);
		map.put("RCV_PORT", rcvPort);
		map.put("SEND_EMAIL_COUNT", sendEmailCount);
		map.put("PASSWORD", password);

		String orgId = ThreadContextHelper.getOrgId();
		String deptId = ThreadContextHelper.getOrgId();

		String defaultUseDaysid = this.useConfigService.findIdByKeyWordForOrgId("DEFAULT_USE_DAYS", orgId);
		String defaultBorrowDaysid = this.useConfigService.findIdByKeyWordForOrgId("DEFAULT_BORROW_DAYS", orgId);
		String defaultBorrowNumid = this.useConfigService.findIdByKeyWordForOrgId("DEFAULT_BORROW_NUM", orgId);
		String borrowForcastDaysid = this.useConfigService.findIdByKeyWordForOrgId("BORROW_FORCAST_DAYS", orgId);

		String defaultBorrowTypeid = this.useConfigService.findIdByKeyWordForOrgId("DEFAULT_BORROW_TYPE", orgId);
		String isHighSetid = this.useConfigService.findIdByKeyWordForOrgId("IS_HIGH_SET", orgId);
		String isBorrowForcastid = this.useConfigService.findIdByKeyWordForOrgId("IS_BORROW_FORCAST", orgId);

		String forcastQueueNumid = this.useConfigService.findIdByKeyWordForOrgId("FORCAST_QUEUE_NUM", orgId);
		String forcastOvertimeid = this.useConfigService.findIdByKeyWordForOrgId("FORCAST_OVERTIME", orgId);
		String psnMsgMaxRcdsid = this.useConfigService.findIdByKeyWordForOrgId("PSN_MSG_MAX_RCDS", orgId);

		String isEmailid = this.useConfigService.findIdByKeyWordForOrgId("IS_EMAIL", orgId);

		String sendSvrid = this.useConfigService.findIdByKeyWordForOrgId("SEND_SVR", orgId);
		String sendPortid = this.useConfigService.findIdByKeyWordForOrgId("SEND_PORT", orgId);
		String rcvSvrid = this.useConfigService.findIdByKeyWordForOrgId("RCV_SVR", orgId);
		String rcvPortid = this.useConfigService.findIdByKeyWordForOrgId("RCV_PORT", orgId);
		String sendEmailCountid = this.useConfigService.findIdByKeyWordForOrgId("SEND_EMAIL_COUNT", orgId);
		String passwordid = this.useConfigService.findIdByKeyWordForOrgId("PASSWORD", orgId);
		// 默认利用天数
		if (!"".equals(defaultUseDaysid)) {
			this.useConfigService.updatedefaultUseDaysKeyValue(map, defaultUseDaysid);
		} else {
			if (!"".equals(map.get("DEFAULT_USE_DAYS"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "DEFAULT_USE_DAYS", map.get("DEFAULT_USE_DAYS"));
			}
		}
		// 默认续借天数
		if (!"".equals(defaultBorrowDaysid)) {
			this.useConfigService.updatedefaultBorrowDaysKeyValue(map, defaultBorrowDaysid);
		} else {
			if (!"".equals(map.get("DEFAULT_BORROW_DAYS"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "DEFAULT_BORROW_DAYS", map.get("DEFAULT_BORROW_DAYS"));
			}
		}
		// 默认续借次数
		if (!"".equals(defaultBorrowNumid)) {
			this.useConfigService.updatedefaultBorrowNumKeyValue(map, defaultBorrowNumid);
		} else {
			if (!"".equals(map.get("DEFAULT_BORROW_NUM"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "DEFAULT_BORROW_NUM", map.get("DEFAULT_BORROW_NUM"));
			}
		}
		// 借还预警天数
		if (!"".equals(borrowForcastDaysid)) {
			this.useConfigService.updateborrowForcastDaysKeyValue(map, borrowForcastDaysid);
		} else {
			if (!"".equals(map.get("BORROW_FORCAST_DAYS"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "BORROW_FORCAST_DAYS", map.get("BORROW_FORCAST_DAYS"));
			}
		}

		// 默认借阅类型（1：原件、2：复制件）
		if (!"".equals(defaultBorrowTypeid)) {
			this.useConfigService.updatededefaultBorrowTypeKeyValue(defaultBorrowTypeid, map.get("DEFAULT_BORROW_TYPE"));
		} else {
			if (!"".equals(map.get("DEFAULT_BORROW_TYPE"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "DEFAULT_BORROW_TYPE", map.get("DEFAULT_BORROW_TYPE"));
			}
		}

		// 是否启用高级设置（1：启用、2：不启用）
		if (!"".equals(isHighSetid)) {
			if (map.get("IS_HIGH_SET").equals("1")) {
				this.useConfigService.updateValueStart(isHighSetid);
			} else {
				this.useConfigService.updateValueEnd(isHighSetid);
			}
		} else {
			if (map.get("IS_HIGH_SET") != null && !"".equals(map.get("IS_HIGH_SET"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "IS_HIGH_SET", map.get("IS_HIGH_SET"));
			}
		}
		// 是否启用借阅预约（1：启用、2：不启用）
		if (isBorrowForcastid != null && !"".equals(isBorrowForcastid)) {
			if (map.get("IS_BORROW_FORCAST").equals("1")) {
				this.useConfigService.updateisBorrowForcastKeyValueStart(isBorrowForcastid);
			} else {
				this.useConfigService.updateisBorrowForcastKeyValueEnd(isBorrowForcastid);
			}
		} else {
			if (map.get("IS_BORROW_FORCAST") != null && !"".equals(map.get("IS_BORROW_FORCAST"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "IS_BORROW_FORCAST", map.get("IS_BORROW_FORCAST"));
			}
		}
		// 预约队列数量
		if (forcastQueueNumid != null && !"".equals(forcastQueueNumid)) {
			this.useConfigService.updateforcastQueueNumKeyValue(map, forcastQueueNumid);
		} else {
			if (map.get("FORCAST_QUEUE_NUM") != null && !"".equals(map.get("FORCAST_QUEUE_NUM"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "FORCAST_QUEUE_NUM", map.get("FORCAST_QUEUE_NUM"));
			}
		}
		// 预约超时时间
		if (forcastOvertimeid != null && !"".equals(forcastOvertimeid)) {
			this.useConfigService.updateforcastOvertimeKeyValue(map, forcastOvertimeid);
		} else {
			if (map.get("FORCAST_OVERTIME") != null && !"".equals(map.get("FORCAST_OVERTIME"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "FORCAST_OVERTIME", map.get("FORCAST_OVERTIME"));
			}
		}
		// 个人消息最大记录数
		if (psnMsgMaxRcdsid != null && !"".equals(psnMsgMaxRcdsid)) {
			this.useConfigService.updatepsnMsgMaxRcdsKeyValue(map, psnMsgMaxRcdsid);
		} else {
			if (map.get("PSN_MSG_MAX_RCDS") != null && !"".equals(map.get("PSN_MSG_MAX_RCDS"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "PSN_MSG_MAX_RCDS", map.get("PSN_MSG_MAX_RCDS"));
			}
		}
		// 是否邮箱通知（1：启用、2：不启用）
		if (isEmailid != null && !"".equals(isEmailid)) {
			if (map.get("IS_EMAIL").equals("1")) {
				this.useConfigService.updateisEmailKeyValueStart(isEmailid);
				// 发件服务器
				if (sendSvrid != null && !"".equals(sendSvrid)) {
					this.useConfigService.updatesendSvrKeyValue(map, sendSvrid);
				} else {
					if (map.get("SEND_SVR") != null && !"".equals(map.get("SEND_SVR"))) {
						this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "SEND_SVR", map.get("SEND_SVR"));
					}
				}
				// 发件端口
				if (sendPortid != null && !"".equals(sendPortid)) {
					this.useConfigService.updatesendPortKeyValue(map, sendPortid);
				} else {
					if (map.get("SEND_PORT") != null && !"".equals(map.get("SEND_PORT"))) {
						this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "SEND_PORT", map.get("SEND_PORT"));
					}
				}
				// 收件服务器
				if (rcvSvrid != null && !"".equals(rcvSvrid)) {
					this.useConfigService.updatercvSvrKeyValue(map, rcvSvrid);
				} else {
					if (map.get("RCV_SVR") != null && !"".equals(map.get("RCV_SVR"))) {
						this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "RCV_SVR", map.get("RCV_SVR"));
					}
				}
				// 收件端口
				if (rcvPortid != null && !"".equals(rcvPortid)) {
					this.useConfigService.updatercvPortKeyValue(map, rcvPortid);
				} else {
					if (map.get("RCV_PORT") != null && !"".equals(map.get("RCV_PORT"))) {
						this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "RCV_PORT", map.get("RCV_PORT"));
					}
				}
			} else {
				this.useConfigService.updateisEmailKeyValueEnd(isEmailid);
			}
		} else {
			if (map.get("IS_EMAIL") != null && !"".equals(map.get("IS_EMAIL"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "IS_EMAIL", map.get("IS_EMAIL"));
			}
		}
		// 发件人账户
		if (sendEmailCountid != null && !"".equals(sendEmailCountid)) {
			this.useConfigService.updateSendEmailCountKeyValue(map, sendEmailCountid);
		} else {
			if (map.get("SEND_EMAIL_COUNT") != null && !"".equals(map.get("SEND_EMAIL_COUNT"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "SEND_EMAIL_COUNT", map.get("SEND_EMAIL_COUNT"));
			}
		}
		// 发件人密码
		if (passwordid != null && !"".equals(passwordid)) {
			this.useConfigService.updatePasswordKeyValue(map, passwordid);
		} else {
			if (map.get("PASSWORD") != null && !"".equals(map.get("PASSWORD"))) {
				this.useSetIntfsService.createUseSetInfoByIntfs(orgId, deptId, sysId, "PASSWORD", map.get("PASSWORD"));
			}
		}
		return mav;
	}

	/**
	 * 获取利用类型通用代码
	 * 
	 * @author
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@RequestMapping("/getUseType")
	public String getUseType(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Collection<SysLookupSimpleVo> lantopUseTypeList = upLoader.getLookUpListByType("LANTOP_USE_TYPE");
		Iterator<SysLookupSimpleVo> iter = lantopUseTypeList.iterator();
		if (iter.hasNext()) {
			StringBuffer sb = new StringBuffer();
			String sbString = "";
			try {
				while (iter.hasNext()) {
					SysLookupSimpleVo simpleVo = iter.next();
					sb.append("{\"id\":\"" + simpleVo.getLookupCode() + "\",");
					sb.append("\"text\":\"" + simpleVo.getLookupName() + "\"},");
				}
				sbString = sb.substring(0, sb.length() - 1);
				sbString = "[" + sbString + "]";
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();
				out.write(sbString);
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 获取密级通用代码
	 * 
	 * @author
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@RequestMapping("/getSecretName")
	public String getSecretName(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Collection<SysLookupSimpleVo> secretLevelList = upLoader.getLookUpListByType("CBB_SECRET");
		Iterator<SysLookupSimpleVo> iter = secretLevelList.iterator();
		if (iter.hasNext()) {
			StringBuffer sb = new StringBuffer();
			String sbString = "";
			try {
				while (iter.hasNext()) {
					SysLookupSimpleVo simpleVo = iter.next();
					sb.append("{\"id\":\"" + simpleVo.getLookupCode() + "\",");
					sb.append("\"text\":\"" + simpleVo.getLookupName() + "\"},");
				}
				sbString = sb.substring(0, sb.length() - 1);
				sbString = "[" + sbString + "]";
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();
				out.write(sbString);
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

	/**
	 * 利用配置信息回显
	 * @author 胡光昌
	 * @param request
	 * @return
	 * @throws Exception ModelAndView
	 * @throws
	 */
	@RequestMapping("/findUseConfig")
	public ModelAndView findUseConfig(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mav = new ModelAndView();
		Map<String, String> map = this.useConfigService.findConfig(ThreadContextHelper.getOrgId(), ThreadContextHelper.getOrgId());
		mav.addObject("map", map);
		mav.setViewName("avicit/im/lantop/basic/useconfig/UseConfigManager");
		return mav;
	}

	/**
	 * 获取系统通用代码类型为“CBB_SECRET”的密级个数
	 * 
	 * @author
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 *             String
	 * @throws
	 */
	@RequestMapping("/getCbbSecretNum")
	@ResponseBody
	public Map<String,Object> getCbbSecretNum(HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String,Object> map = new HashMap<>();
		Collection<SysLookupSimpleVo> cbbSecretList = upLoader.getLookUpListByType("CBB_SECRET");
		Collection<SysLookupSimpleVo> lantopUseType = upLoader.getLookUpListByType("LANTOP_USE_TYPE");
		Iterator<SysLookupSimpleVo> iter = cbbSecretList.iterator();
		int secretNum = 0;
		while (iter.hasNext()) {
			secretNum++;
		}
		Iterator<SysLookupSimpleVo> iterUseType = lantopUseType.iterator();
		int useTypeNum = 0;
		while (iterUseType.hasNext()) {
			useTypeNum++;
		}
		map.put("secretNum", secretNum);
		map.put("useTypeNum", useTypeNum);
		return map;
	}

}
